package com.gandong8.trace.tool.core;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Component
@Aspect
@Slf4j
public class TraceAspect {
    @Pointcut("@annotation(com.gandong8.trace.tool.annotation.Trace)")
    private void trace(){}
    @Around("trace()")
    private static Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        long startTime = SystemClock.now();
        Object result = joinPoint.proceed();
        long cost = SystemClock.now() - startTime;
        log.warn("traceAspect:{},{},{}", cost, joinPoint.getSignature().getName(), joinPoint.getArgs());
        return result;
    }

}
